package com.henu.ocr.service.serviceImpl;

import com.henu.ocr.service.RabbitMQService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import com.henu.ocr.CommonConstant;

@Service
@SuppressWarnings("all")
public class RabbitMQServiceImpl implements RabbitMQService {
    private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Resource
    private RabbitTemplate rabbitTemplate;

    @Override
    public String sendMsg(String msg) throws Exception {
        try {
            String msgId = UUID.randomUUID().toString().replace("-", "").substring(0, 32);
            String sendTime = SDF.format(new Date());
            rabbitTemplate.convertAndSend(CommonConstant.EXCHANGE_NAME,CommonConstant.ROUTING_KEY, msg);
            return "ok";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }
}